package com.zzyl.controller;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.BedDto;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedQueryVo;
import com.zzyl.vo.BedVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bed")
@Api(tags = "床位管理相关接口")
public class BedController extends BaseController {

    @Autowired
    private BedService bedService;

    @ApiOperation("新增床位")
    @PostMapping("/create")
    public ResponseResult createBed(@RequestBody BedDto bedDto) {
        int row = bedService.createBed(bedDto);
        return this.toAjax(row);
    }

    @ApiOperation("删除床位")
    @DeleteMapping("/delete/{id}")
    public ResponseResult deleteBed(@PathVariable("id") Long id) {
        int row = bedService.deleteBed(id);
        return this.toAjax(row);
    }


    @ApiOperation("更新床位")
    @PutMapping("/update")
    public ResponseResult updateBed(@RequestBody BedDto bedDto) {
        int row = bedService.updateBed(bedDto);
        return this.toAjax(row);

    }


    @ApiOperation("根据床位id查询床位信息")
    @GetMapping("/read/{id}")
    public ResponseResult<BedQueryVo> readBed(@PathVariable("id") Long id) {   // 不能省略
        return this.success(bedService.selectById(id));
    }


    @ApiOperation("根据房间id查询床位信息")
    @GetMapping("/read/room/{roomId}")
    public ResponseResult<List<BedVo>> readBedByRoomId(
            @ApiParam(value = "房间ID", required = true)  // 我不想写这句话
            @PathVariable Long roomId) {
        List<BedVo> bedVoList = bedService.getBedsByRoomId(roomId);
        return this.success(bedVoList);
    }

}
